
// Copyright (c) WanSheng Intelligent Corp. All rights reserved.
// Licensed under the LGPL v3.0 license

#ifndef __S7_PLUGIN_H__
#define __S7_PLUGIN_H__

#include "module.h"
#include <pthread.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <printf.h>
#include <errno.h>
#include <sys/stat.h>
#include <linux/prctl.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/prctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <limits.h>
#include <ctype.h>

#include "setport.h"
#include "openSocket.h"
#include "wa_plugin_sdk.h"
#include "nodave.h"
#include "path.h"
#include "logs.h"
#include "agent_core_lib.h"
#include "wa_bus.h"
#include "misc.h"
#include "er-coap-constants.h"
#include "misc.h"
#include "cJSON_ext.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define PLUGIN_NAME "s7_plugin"   // must be same with the name in the plugin.manifest!
#define LOG_TAG "s7"
#define MAX_S7_DEVICE 50

    typedef struct _s7_device_t
    {
        char *uuid;
        char *name;
        int protocol;
        int useSpeed;
        int mpi_addr;
        int rack;
        int slot;
        int MPI;
        daveInterface *di;
        daveConnection *dc;
        wa_plugin_device_info_t *plugin_cfg;
    } s7_device_t;

    extern s7_device_t *g_s7_devices[MAX_S7_DEVICE];

    extern void open_s7_device(s7_device_t *device);
    extern s7_device_t *find_device_open(const char *di);
    extern bool load_device_config(const char * plugin_name);

    extern void res_s7_cmd_get_handler(restful_request_t *request, REQ_ENV_HANDLE);
    extern void res_s7_cmd_put_handler(restful_request_t *request, REQ_ENV_HANDLE);

#ifdef __cplusplus
}
#endif

#endif
